﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VIP.Extension;

/// <summary>
/// 双击定位（需要EventSystem、相机上Physics Raycaster）
/// </summary>
public class DoubleLocation : MonoBehaviour {

    private VIPCamera vipCamera;
    private VIPButton doubleBtn;
    private static GameObject obj;

    private void Start()
    {
        vipCamera = FindObjectOfType<VIPCamera>();
        doubleBtn = GetComponent<VIPButton>();
        if (doubleBtn.IsNull()) {
            doubleBtn = gameObject.AddComponent<VIPButton>();
        }
        doubleBtn.onDouble.AddListener(() =>
        {
            vipCamera.Focus(transform);
            gameObject.HighlighterOn();
            if (obj.IsNotNull())
            {
                obj.HighlighterOff();
                obj = gameObject;
                obj.HighlighterOn();
            }
            else {
                obj = gameObject;
                obj.HighlighterOn();
            }
        
        });
    }

}
